
export const getImgPath = (path) => {//传递过来的图片地址需要处理后才能正常使用
    let suffix;
    if (!path) {
        return '//elm.cangdu.org/img/default.jpg'
    }
    if (path.indexOf('jpeg') !== -1) {
        suffix = '.jpeg'
    } else {
        suffix = '.png'
    }
    let url = '/' + path.substr(0, 1) + '/' + path.substr(1, 2) + '/' + path.substr(3) + suffix;
    return 'https://fuss10.elemecdn.com' + url
}


export const dataAdapter = function (dataSource, targetOption) { //组件的data适配器
    for (let key in targetOption) {
        if (key in this) { // 必须声明过
            let data = {}
            let mapping = targetOption[key]
            for (let key in mapping) {
                let sourceKey = mapping[key]
                if (typeof sourceKey === 'function') { // 使用getter返回值
                    data[key] = sourceKey(dataSource)
                } else if (sourceKey === true) {
                    data[key] = dataSource[key]
                } else { // 从原始数据中适配出目标数据
                    data[key] = dataSource[sourceKey]
                }
            }
            if (this[key]) {
                Object.assign(this[key], data)
            } else {
                this[key] = data
            }
        }
    }
}